package com.eastedu.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.eastedu.common.util.SchoolGroupMappingUtil;
import com.eastedu.repository.lesson.mapper.PreparationMapper;
import com.eastedu.repository.lesson.po.PreparationPO;
import com.eastedu.service.AbstractDataSyncService;
import com.eastedu.service.DataSourceService;
import org.springframework.stereotype.Service;


/**
 * 〈〉
 *
 * @author ZHISHUAI.ZHANG
 * @since 2021 /7/28
 */
@Service("lesson-source")
@DS("lesson")
public class LessonDataSourceServiceImpl extends AbstractDataSyncService<PreparationPO> implements DataSourceService {

    /**
     * Instantiates a new Lesson data source service.
     *
     * @param preparationMapper the preparation mapper
     */
    public LessonDataSourceServiceImpl(PreparationMapper preparationMapper) {
        super(preparationMapper);
        /// super.addScriptByTableName("t_preparation");
        super.addScript("UPDATE t_preparation t1 SET t1.sync_state = 0 \n" +
                                "WHERE school_group_id IS NULL OR school_group_id = 0");
    }

    @Override
    protected void updateContent(PreparationPO preparationPo) {
        preparationPo.setSchoolGroupId(SchoolGroupMappingUtil.mappingId(preparationPo.getSchoolId()));
    }

}